package com.zrwl.poscloud.xo.service.impl;
import com.zrwl.poscloud.base.entity.MessageRemind;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrwl.poscloud.base.enums.EStatus;
import com.zrwl.poscloud.base.superI.SuperServiceImpl;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.utils.StringUtils;
import com.zrwl.poscloud.xo.global.MessageConf;
import com.zrwl.poscloud.xo.global.SQLConf;
import com.zrwl.poscloud.xo.global.SysConf;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import com.zrwl.poscloud.xo.mapper.MessageRemindMapper;
import com.zrwl.poscloud.xo.service.MessageRemindService;
import com.zrwl.poscloud.xo.vo.MessageRemindVO;
/**
 * 消息提醒 服务实现类
 *
 * @author 刘思童 AutoGenerate
 * @date 2023-03-17
 */
@Service
public class MessageRemindServiceImpl extends SuperServiceImpl<MessageRemindMapper,MessageRemind> implements MessageRemindService {

    @Autowired
    private MessageRemindService messageRemindService;
    @Override
    public IPage<MessageRemind> getPageList(MessageRemindVO messageRemindVO){
       QueryWrapper<MessageRemind> queryWrapper = new QueryWrapper<>();
       if (StringUtils.isNotEmpty(messageRemindVO.getKeyword()) && !StringUtils.isEmpty(messageRemindVO.getKeyword().trim())) {
            queryWrapper.like("name", messageRemindVO.getKeyword().trim());
       }
       Page<MessageRemind> page = new Page<>();
       page.setCurrent(messageRemindVO.getCurrentPage());
       page.setSize(messageRemindVO.getPageSize());
       queryWrapper.ne(SQLConf.STATUS, EStatus.DISABLED);
       queryWrapper.orderByDesc(SQLConf.CREATE_TIME);
       IPage<MessageRemind> pageList = messageRemindService.page(page, queryWrapper);
       List<MessageRemind> list = pageList.getRecords();
       pageList.setRecords(list);
       return pageList;
}
    @Override
    public List<MessageRemind> getAllList(MessageRemindVO messageRemindVO){
        QueryWrapper<MessageRemind> queryWrapper = new QueryWrapper<>();
        queryWrapper.ne(SQLConf.STATUS, EStatus.DISABLED);
        queryWrapper.orderByAsc(SQLConf.CREATE_TIME);
        List<MessageRemind> list = messageRemindService.list(queryWrapper);
        return list;
}
    @Override
    public String add(MessageRemindVO messageRemindVO){
        MessageRemind entity = new MessageRemind();
        BeanUtils.copyProperties(messageRemindVO, entity, SysConf.STATUS);
        entity.insert();
        messageRemindVO.setUid(entity.getUid());
        return ResultUtil.successWithMessage(MessageConf.INSERT_SUCCESS);}
    @Override
    public String edit(MessageRemindVO messageRemindVO){
        MessageRemind entity = messageRemindService.getById(messageRemindVO.getUid());
        BeanUtils.copyProperties(messageRemindVO, entity);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
    @Override
    public String delete(MessageRemindVO messageRemindVO){
        MessageRemind entity = messageRemindService.getById(messageRemindVO.getUid());
        entity.setStatus(EStatus.DISABLED);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
}
